<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script>
        $(function () {
            $("#tab").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/scell/queryScellChenge",
                striped: true,
                pageNumber: 1,
                pagination: true,
                sidePagination: 'server',
                pageSize: 3,
                pageList: [3, 5, 6, 10],
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNumber: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,
                    }
                },
                columns: [
                    {title: '配置单编号', field: 'storeId', align: 'center'},
                    {title: '产品编号', field: 'productId', align: 'center'},
                    {title: '产品名称', field: 'productName', align: 'center'},
                    {title: 'I级分类', field: 'firstKindName', align: 'center'},
                    {title: 'II级分类', field: 'secondKindName', align: 'center'},
                    {title: 'III级分类', field: 'thirdKindName', align: 'center'},
                    {title: '登记时间', field: 'registerTime', align: 'center'},
                    {
                        title: '操作', field: 'id', align: 'center',
                        formatter: function (value, row, index) {
                            var btn1 = "<button  class='btn btn-primary btn-sm' onclick='edit(" + JSON.stringify(row) + ")' data-toggle='modal' data-target='#myModal2'>变更</button>";
                            return btn1;
                        }
                    },
                ]
            })
        });

        function findAcc() {
            $.ajax({
                type: 'post',
                url: '/SysUser/queryUser',
                success: function (result) {
                    $("#registrar").val(result.loginId);
                }
            })
        }

        var zdObj = null;

        function edit(data) {
            zdObj = data;
            findAcc();
            $("#id").val(data.id);
            var date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            let odate = date.getDate();
            let hour = date.getHours()
            let minute = date.getMinutes()
            let second = date.getSeconds()
            var dataStr = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
            $("#kxMax").val(data.maxAmount);
            $("#kxMin").val(data.minAmount);
            $("#inputname").val(data.productName);
            $("#inputid").val(data.productId);
            let id = data.firstKindId + "-" + data.secondKindId + "-" + data.thirdKindId
            let name = data.firstKindName + "-" + data.secondKindName + "-" + data.thirdKindName;
            $("#tbody").html("");
            $("#tbody").append("<tr><td>" +
                data.id + "</td><td>" +
                "成品库</td><td>" +
                id + "</td><td>" +
                name + "</td><td>" +
                "<input id='Maxcount' value='" + data.maxCapacityAmount + "' style=\"width: 100%;\" class=\"form-control-plaintext\"></td>" +

                "</tr>")
            $("#date").val(dataStr);
            $("#storeId").val(data.storeId);
            $("#config").val(data.config);
        }

        function changeScell() {
            $.ajax({
                type: 'post',
                url: '/scell/ScellChange',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify({
                    id: $("#id").val(),
                    storeId: $("#storeId").val(),
                    productId: zdObj.productId,
                    productName: zdObj.productName,
                    firstKindId: zdObj.firstKindId,
                    firstKindName: zdObj.firstKindName,
                    secondKindId: zdObj.secondKindId,
                    secondKindName: zdObj.secondKindName,
                    thirdKindId: zdObj.thirdKindId,
                    thirdKindName: zdObj.thirdKindName,
                    minAmount: $("#kxMin").val(),
                    maxAmount: $("#kxMax").val(),
                    maxCapacityAmount: $("#Maxcount").val(),
                    config: $("#config").val(),
                    register: $("#registrar").val(),
                    registerTime: $("#date").val(),
                    checkTag: '待审核'
                }),
                success: function (result) {
                    if (result == 'ok') {
                        alert("变更成功！");
                        $("#tab").bootstrapTable("refresh");
                    }
                }

            })
        }
    </script>
</head>
<body>
<table id="tab">

</table>

<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">安全库存配置单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">


                <div class="form-group row">
                    <input type="hidden" id="id">
                    <label for="storeId" class="col-sm-2 col-form-label">库存编号</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="storeId" readonly>
                    </div>
                </div>

                <div class="form-group row">

                    <label for="inputname" class="col-sm-2 col-form-label">产品名称</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="inputname" readonly>
                    </div>
                    <div class="col-2"></div>
                    <label for="inputid" class="col-sm-2 col-form-label">产品编号</label>
                    <div class="col-sm-3">
                        <input type="text   " class="form-control" id="inputid" readonly>
                    </div>
                </div>

                <div class="form-group row">

                    <label for="kxMin" class="col-sm-2 col-form-label">库存报警下限数：</label>
                    <div class="col-sm-3">
                        <input type="number" class="form-control" id="kxMin">
                    </div>
                    <div class="col-2">
                    </div>
                    <label for="kxMax" class="col-sm-2 col-form-label">库存报警上限数：</label>
                    <div class="col-sm-3 container">
                        <input type="number" class="form-control " id="kxMax" data-toggle="tooltip" data-placement="top"
                               data-content="提示">
                    </div>
                </div>

                <div class="form-group row">


                </div>


                <div>
                    <table class="table table-striped" border="1">
                        <thead class="table-primary ">
                        <tr>
                            <td>序号</td>
                            <td>库房名称</td>
                            <td>存储地址编号</td>
                            <td>存在地址名称</td>

                            <td>最大存储量</td>

                        </tr>
                        </thead>
                        <tbody id="tbody">
                        </tbody>
                    </table>
                </div>

                <div class="form-group row">

                    <label for="registrar" class="col-sm-2 col-form-label">变更人：</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="registrar">
                    </div>
                    <div class="col-2"></div>
                    <label for="date" class="col-sm-2 col-form-label">变更时间：</label>
                    <div class="col-sm-3">
                        <input type="datetime" class="form-control" id="date">
                    </div>
                </div>

                <div class="form-group">
                    <label for="config">配置需求</label>
                    <textarea class="form-control" id="config" rows="3"></textarea>
                </div>

            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="changeScell()">提交</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
</body>
</html>